package j01set;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;

public class J1 {
    public static void main(String[] args) {
        HashSet<String> hs = new HashSet<>();
        hs.add("b");
        hs.add("a");
        hs.add("a");
        hs.add("c");
        System.out.println("hs = " + hs);
        System.out.println("====");
        ArrayList<String> arr1 = new ArrayList<>(
                Arrays.asList("aa","bb","bb","cc")
        );
        HashSet<String> hs2 = new HashSet<>(arr1);
        System.out.println("hs2 = " + hs2);
        /**
         * 100  0.75
         * 100*0.75 = 75   100*2=200
         * 200*0.75 = 150  200*2 = 200
         */
    }
}

class J2contains{
    public static void main(String[] args) {
        HashSet<String> hs1 = new HashSet<>();
        hs1.add("a");
        hs1.add("b");

        System.out.println(hs1.contains("a"));
        System.out.println("====");
        class Cat{
            int age;

            public Cat(int age) {
                this.age = age;
            }

            @Override
            public boolean equals(Object o) {
                if (this == o) return true;
                if (o == null || getClass() != o.getClass()) return false;
                Cat cat = (Cat) o;
                return age == cat.age;
            }

            @Override
            public int hashCode() {
                return Objects.hash(age);
            }
        }
        HashSet<Cat> catArr = new HashSet<>();
        Cat c1 = new Cat(2);
        catArr.add(c1);
        System.out.println(catArr.contains(c1));
        //1，先看hashCode是否一样
        //2，先看equals是否一样
        System.out.println(catArr.contains(new Cat(2)));;
    }
}

